import { _decorator, Component, Node, resources, SpriteFrame } from 'cc';
import { BaseManager } from './BaseManager';
import { Coin } from '../items/common/Coin';
import { MDClear } from '../items/props/MergeDish/MDClear';
import { MDRefresh } from '../items/props/MergeDish/MDRefresh';
import { MDUncover } from '../items/props/MergeDish/MDUncover';
import { BaseItem } from '../items/BaseItem';
import { _player } from '../Main';
const { ccclass, property } = _decorator;

@ccclass('ItemManager')
export class ItemManager extends BaseManager {

    managerName: string = '物品管理器'

    items = {
        Coin: new Coin(),
        MDClear: new MDClear(),
        MDRefresh: new MDRefresh(),
        MDUncover: new MDUncover(),
    }

    init(): void {
        for (let key in this.items) {
            this.loadItemIcon(key)
        }
        for (let key in this.items) {
            let item: BaseItem = this.items[key]
            _player.loadShopLimit(item.getLimitName())
        }
    }

    loadItemIcon(key: string) {
        let name: string = key.toLowerCase()
        resources.load('textures/items/' + name + '/spriteFrame', SpriteFrame, (err, asset) => {
            if (err)  {
                return console.log('加载错误：', err)
            }
            this.items[key].icon = asset ? asset as SpriteFrame : null
        })
    }
}


